package cz.najman.emdroid.ui;

import com.markupartist.android.widget.ActionBar;

import cz.najman.emdroid.R;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;

public class ActionBarActivity extends Activity {
	
	/**
	 * Key intended to be used in intent to supply an 
	 * users ID to the activity.
	 */
	public static final String USER_ID = "userId";
	
	/**
	 * Key intended to be used in intent to supply an 
	 * event ID to the activity.
	 */
	public static final String EVENT_ID = "eventId";
	
	protected ActionBar mActionBar;
	private Resources mResources;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		mResources = getResources();		
		super.onCreate(savedInstanceState);
	}

	/**
	 * Sets the actionbar title.
	 * @param title to be displayed in the actionbar
	 */
	protected void setActionBarTitle(String title) {
		if (mActionBar == null) initializeActionBar();
		mActionBar.setTitle(title);
	}
	
	protected void setActionBarTitle(int titleId){		
		final String title = mResources.getString(titleId);
		setActionBarTitle(title);
	}

	protected void setActionBarHomeAction(Intent intent, int icon){
		if (mActionBar == null) initializeActionBar();
		mActionBar.setHomeAction( new ActionBar.IntentAction(this,intent,icon) );
	}
	
	protected void setActionBarHomeAction(Intent intent){
		setActionBarHomeAction(intent, R.drawable.ic_menu_home);
	}
	
	private void initializeActionBar(){
		mActionBar = (ActionBar) findViewById(R.id.actionbar);
	}
	
}
